/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bg.tu.varna.pms.client.gui;

import java.awt.CardLayout;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;

import javax.swing.JOptionPane;

import bg.tu.varna.pms.client.listener.ContactlistListener;

/**
 * 
 * @author plam40
 */
public class ContactListFrame extends javax.swing.JFrame {

	private static final long serialVersionUID = 3458005772961338957L;

	/**
	 * Creates new form ContactListFrame
	 */
	public ContactListFrame(ActionListener controller) {
		setNimbusLookAndFeel();

		initComponents();

		showLogin(controller);
		setTitle("Mype");
//		loginPanel2.addController(controller);
		// registerPanel2.addController(controller);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// <editor-fold defaultstate="collapsed"
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        registerPanel2 = new bg.tu.varna.pms.client.gui.RegisterPanel();
        contactListPanel2 = new bg.tu.varna.pms.client.gui.ContactListPanel();
        loginPanel2 = new bg.tu.varna.pms.client.gui.LoginPanel();
        jPanel2 = new javax.swing.JPanel();
        userGroupPanel1 = new bg.tu.varna.pms.client.gui.UserGroupPanel();

        jLabel1.setIcon(MediaManager.getInstance().getIconAddUser());

        jLabel2.setIcon(MediaManager.getInstance().getIconDeleteUser());

        jLabel3.setIcon(MediaManager.getInstance().getIconAddGroup());

        jLabel4.setIcon(MediaManager.getInstance().getIconDeleteGroup());

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel3.setLayout(new java.awt.CardLayout());
        jPanel3.add(registerPanel2, ContactListFrameCardsEnum.REGISTER_PANEL.name());
        jPanel3.add(contactListPanel2, ContactListFrameCardsEnum.CONTACT_LIST_PANEL.name());
        jPanel3.add(loginPanel2, ContactListFrameCardsEnum.LOGIN_PANEL.name());

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 3, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 40, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
                    .addComponent(userGroupPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
                .addGap(0, 0, 0)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(userGroupPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, 0)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void setNimbusLookAndFeel() {
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
					.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger
					.getLogger(ContactListFrame.class.getName()).log(
							java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger
					.getLogger(ContactListFrame.class.getName()).log(
							java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger
					.getLogger(ContactListFrame.class.getName()).log(
							java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger
					.getLogger(ContactListFrame.class.getName()).log(
							java.util.logging.Level.SEVERE, null, ex);
		}
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
//	jPanel3.add(registerPanel2, ContactListFrameCardsEnum.REGISTER_PANEL.name());
//    jPanel3.add(contactListPanel2, ContactListFrameCardsEnum.CONTACT_LIST_PANEL.name());
//    jPanel3.add(loginPanel2, ContactListFrameCardsEnum.LOGIN_PANEL.name());
	
	// public static void main(String args[]) {
	// /* Set the Nimbus look and feel */
	// // <editor-fold defaultstate="collapsed"
	// // desc=" Look and feel setting code (optional) ">
	// /*
	// * If Nimbus (introduced in Java SE 6) is not available, stay with the
	// * default look and feel. For details see
	// * http://download.oracle.com/javase
	// * /tutorial/uiswing/lookandfeel/plaf.html
	// */
	// try {
	// for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
	// .getInstalledLookAndFeels()) {
	// if ("Nimbus".equals(info.getName())) {
	// javax.swing.UIManager.setLookAndFeel(info.getClassName());
	// break;
	// }
	// }
	// } catch (ClassNotFoundException ex) {
	// java.util.logging.Logger
	// .getLogger(ContactListFrame.class.getName()).log(
	// java.util.logging.Level.SEVERE, null, ex);
	// } catch (InstantiationException ex) {
	// java.util.logging.Logger
	// .getLogger(ContactListFrame.class.getName()).log(
	// java.util.logging.Level.SEVERE, null, ex);
	// } catch (IllegalAccessException ex) {
	// java.util.logging.Logger
	// .getLogger(ContactListFrame.class.getName()).log(
	// java.util.logging.Level.SEVERE, null, ex);
	// } catch (javax.swing.UnsupportedLookAndFeelException ex) {
	// java.util.logging.Logger
	// .getLogger(ContactListFrame.class.getName()).log(
	// java.util.logging.Level.SEVERE, null, ex);
	// }
	// // </editor-fold>
	//
	// /* Create and display the form */
	// java.awt.EventQueue.invokeLater(new Runnable() {
	// public void run() {
	// ContactListFrame frame = new ContactListFrame(null);
	// // frame.add(new LoginPanel());
	// frame.setVisible(true);
	// }
	// });
	// }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private bg.tu.varna.pms.client.gui.ContactListPanel contactListPanel2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private bg.tu.varna.pms.client.gui.LoginPanel loginPanel2;
    private bg.tu.varna.pms.client.gui.RegisterPanel registerPanel2;
    private bg.tu.varna.pms.client.gui.UserGroupPanel userGroupPanel1;
    // End of variables declaration//GEN-END:variables

	public void showRegister(final ActionListener controller) {
		userGroupPanel1.setVisible(false);
		registerPanel2.addController(controller);
		((CardLayout) jPanel3.getLayout()).show(jPanel3,
				ContactListFrameCardsEnum.REGISTER_PANEL.name());
	}

	public void showLogin(final ActionListener controller) {
		userGroupPanel1.setVisible(false);
		loginPanel2.addController(controller);
		((CardLayout) jPanel3.getLayout()).show(jPanel3,
				ContactListFrameCardsEnum.LOGIN_PANEL.name());
	}

	public void showContactList(final MouseListener userGroupController, final ContactlistListener listener) {
		userGroupPanel1.addController(userGroupController);
		userGroupPanel1.setVisible(true);
		
		((CardLayout) jPanel3.getLayout()).show(jPanel3,
				ContactListFrameCardsEnum.CONTACT_LIST_PANEL.name());
	}
	
	public UserGroupPanel getUserGroupPanel() {
		return userGroupPanel1;
	}
	
	public String getUsernameLogin() {
		return loginPanel2.getUsername();
	}
	
	public char[] getPasswordLogin() {
		return loginPanel2.getPassword();
	}
	
	public String getUsernameRegister() {
		return registerPanel2.getUsername();
	}
	
	public char[] getPasswordRegister() {
		return registerPanel2.getPassword();
	}
	
	public ContactListPanel getContactListPanel() {
		return contactListPanel2;
	}

	public void showErrorMessage(String message) {
		JOptionPane.showMessageDialog(this, message, "Error occured!", JOptionPane.ERROR_MESSAGE);
		
	}
}
